package cn.myplus.uc.user

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

/**
 * @project myplus5
 * @description
 * @author libo
 * @date 2023-10-03 16:24:28
 */
@SpringBootTest
class UserServiceTest(@Autowired val userService: UserService) {

    @Test
    fun getUserById() {
        val user = userService.getUserById("admin")
        assertNotNull(user)
    }

    @Test
    fun getUserByIdEmptyId(){
        val exception: Exception = assertThrows(IllegalArgumentException::class.java) {
            userService.getUserById(id = "")
        }

        val expectedMessage = "查询用户,参数错误"
        val actualMessage = exception.message

        assertTrue(actualMessage!!.contains(expectedMessage))
    }

    @Test
    fun getUsers(){
        val users = userService.getUsers()
        assertNotNull(users)
        assertEquals(15,users.size)
    }
}